/*
 * Copyright © ${project.inceptionYear} organization baomidou
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhou.base.dynamic.ds.test.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.zhou.base.dynamic.ds.test.mapper.UserMapper;
import com.zhou.base.dynamic.ds.test.model.entity.User;
import com.zhou.base.dynamic.ds.test.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 可以得出结论ds的切面优先级低于@DS注解的优先级
 * 可以放开类上的@DS注解
 */
@RequiredArgsConstructor
@Service
//@DS("slave")
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    @Override
    @DS("#session.tenantName")
    public List<User> selectSpelBySession() {
        return userMapper.selectUsers();
    }

    @Override
    @DS("#header.tenantName")
    public List<User> selectSpelByHeader() {
        return userMapper.selectUsers();
    }

    @Override
    @DS("#tenantName")
    public List<User> selectSpelByKey(String tenantName) {
        return userMapper.selectUsers();
    }

    @Override
    @DS("#user.tenantName")
    public List<User> selecSpelByTenant(User user) {
        return userMapper.selectUsers();
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public List<User> selectAll() {
        return userMapper.selectUsers();
    }

    @Override
    public void addUser(User user) {
        userMapper.addUser(user.getName(), user.getAge());
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public void deleteUserById(Long id) {
        userMapper.deleteUserById(id);
    }

    @Override
    public void deleteAll() {
        userMapper.deleteAll();
    }
}
